﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace Twi.COMMON.Core
{
    /*
    * Copyright: ©2010-2011 Twilight软件开发工作室版权所有
     * Create By:xuzhihong
     * Create Date: 2010-12-03
     * Description: 分页条件
     */

    public class PagingCondition
    {
        private bool _needPaging = true;
        /// <summary>
        /// 是否需要分页（默认分页）
        /// </summary>
        public bool needPaging
        {
            get
            {
                return _needPaging;
            }
            set
            {
                _needPaging = value;
            }
        }        
        private int _startIndex = 0;
        /// <summary>
        /// 跳过的系列中指定的条数 默认为0
        /// </summary>
        public int startIndex
        {         
            get
            {
                return _startIndex;
            }
            set
            {
                _startIndex = value;
            }
        }
        
        private int _pageSize=25;
        /// <summary>
        /// 每页显示条数 默认为25
        /// </summary>
        public int pageSize
        {
            get
            {
                return _pageSize;
            }
            set
            {
                _pageSize = value;
            }
        }

        /// <summary>
        /// 获取当前为第几页，从1开始
        /// </summary>
        /// <returns></returns>
        public int GetCurrentPage()
        {
            int currentPage = 1;
            if (startIndex > 0)
            {
                currentPage = Convert.ToInt32(startIndex / pageSize);
                currentPage += startIndex % pageSize == 0 ? 1 : 0;
            }
            return currentPage;
        }

        /// <summary>
        /// 分页所需要的排序字段
        /// </summary>
        public string orderByFields
        {
            get;
            set;
        }
    }
    
}
